/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#ifndef SX_RENDERER_H
#define SX_RENDERER_H

#include <sxAbstractRenderer.h>

namespace Sx {
namespace Graphics {
namespace Rendering {

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
class Renderer : public AbstractRenderer<Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>, BaseGraphicsContextType, BaseObjectType, BasePhysicalRepresentationType> {
public:
	Renderer(const std::shared_ptr<BaseGraphicsContextType>& graphicsContext);
	Renderer(const Renderer& renderer);
	virtual ~Renderer();

	bool construct(BaseGraphicsContextType* const graphicsContext, BaseObjectType* const object, BasePhysicalRepresentationType* const physicalRepresentation);
	void update(BaseGraphicsContextType* const graphicsContext, BaseObjectType* const object, float dt);
	void render(BaseGraphicsContextType* const graphicsContext, BaseObjectType* const object, BasePhysicalRepresentationType* const physicalRepresentation);
};

}

}

}

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
Sx::Graphics::Rendering::Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::Renderer(const std::shared_ptr<BaseGraphicsContextType>& graphicsContext) : AbstractRenderer(graphicsContext) {}

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
Sx::Graphics::Rendering::Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::Renderer(const Renderer& renderer) {
	this->graphicsContext = renderer.graphicsContext;
}

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
Sx::Graphics::Rendering::Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::~Renderer() {}

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
bool Sx::Graphics::Rendering::Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::construct(BaseGraphicsContextType* const graphicsContext, BaseObjectType* const object, BasePhysicalRepresentationType* const physicalRepresentation) {
	static_assert(std::is_base_of<Renderer, RendererImplementationType>::value, "[Renderer:construct] Compile Error: RendererImplementationType must extend class Renderer.");
	static_assert(std::is_base_of<BaseGraphicsContextType, DerivedGraphicsContextType>::value, "[Renderer:construct] Compile Error: GraphicsContextDerivedType must extend GraphicsContextBaseType.");
	static_assert(std::is_base_of<BaseObjectType, DerivedObjectType>::value, "[Renderer:construct] Compile Error: DerivedObjectType must extend BaseObjectType.");
	static_assert(std::is_base_of<BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::value, "[Renderer:construct] Compile Error: DerivedPhysicalRepresentationType must extend BasePhysicalRepresentationType.");

	static_assert(!std::is_same<BaseObjectType, DerivedObjectType>::value, "[Renderer:construct] Compile Error: BaseObjectType and DerivedObjectType cannot be the same type.");
	static_assert(!std::is_same<BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::value, "[Renderer:construct] Compile Error: BasePhysicalRepresentationType and DerivedPhysicalRepresentationType cannot be the same type.");

	return (static_cast<RendererImplementationType*>(this))->construct(static_cast<DerivedGraphicsContextType*>(graphicsContext), static_cast<DerivedObjectType*>(object), static_cast<DerivedPhysicalRepresentationType*>(physicalRepresentation));
}

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
void Sx::Graphics::Rendering::Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::update(BaseGraphicsContextType* const graphicsContext, BaseObjectType* const object, float dt) {
	static_assert(std::is_base_of<Renderer, RendererImplementationType>::value, "[Renderer:construct] Compile Error: RendererImplementationType must extend class Renderer.");
	static_assert(std::is_base_of<BaseGraphicsContextType, DerivedGraphicsContextType>::value, "[Renderer:construct] Compile Error: GraphicsContextDerivedType must extend GraphicsContextBaseType.");
	static_assert(std::is_base_of<BaseObjectType, DerivedObjectType>::value, "[Renderer:construct] Compile Error: DerivedObjectType must extend BaseObjectType.");
	static_assert(std::is_base_of<BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::value, "[Renderer:construct] Compile Error: DerivedPhysicalRepresentationType must extend BasePhysicalRepresentationType.");

	static_assert(!std::is_same<BaseObjectType, DerivedObjectType>::value, "[Renderer:construct] Compile Error: BaseObjectType and DerivedObjectType cannot be the same type.");
	static_assert(!std::is_same<BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::value, "[Renderer:construct] Compile Error: BasePhysicalRepresentationType and DerivedPhysicalRepresentationType cannot be the same type.");

	(static_cast<RendererImplementationType*>(this))->update(static_cast<DerivedGraphicsContextType*>(graphicsContext), static_cast<DerivedObjectType*>(object), dt);
}

template <
	typename RendererImplementationType,
	typename BaseGraphicsContextType,
	typename DerivedGraphicsContextType,
	typename BaseObjectType,
	typename DerivedObjectType,
	typename BasePhysicalRepresentationType,
	typename DerivedPhysicalRepresentationType
	>
void Sx::Graphics::Rendering::Renderer<RendererImplementationType, BaseGraphicsContextType, DerivedGraphicsContextType, BaseObjectType, DerivedObjectType, BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::render(BaseGraphicsContextType* const graphicsContext, BaseObjectType* const object, BasePhysicalRepresentationType* const physicalRepresentation) {
	static_assert(std::is_base_of<Renderer, RendererImplementationType>::value, "[Renderer:construct] Compile Error: RendererImplementationType must extend class Renderer.");
	static_assert(std::is_base_of<BaseGraphicsContextType, DerivedGraphicsContextType>::value, "[Renderer:construct] Compile Error: GraphicsContextDerivedType must extend GraphicsContextBaseType.");
	static_assert(std::is_base_of<BaseObjectType, DerivedObjectType>::value, "[Renderer:construct] Compile Error: DerivedObjectType must extend BaseObjectType.");
	static_assert(std::is_base_of<BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::value, "[Renderer:construct] Compile Error: DerivedPhysicalRepresentationType must extend BasePhysicalRepresentationType.");

	static_assert(!std::is_same<BaseObjectType, DerivedObjectType>::value, "[Renderer:construct] Compile Error: BaseObjectType and DerivedObjectType cannot be the same type.");
	static_assert(!std::is_same<BasePhysicalRepresentationType, DerivedPhysicalRepresentationType>::value, "[Renderer:construct] Compile Error: BasePhysicalRepresentationType and DerivedPhysicalRepresentationType cannot be the same type.");

	(static_cast<RendererImplementationType*>(this))->render(static_cast<DerivedGraphicsContextType*>(graphicsContext), static_cast<DerivedObjectType*>(object), static_cast<DerivedPhysicalRepresentationType*>(physicalRepresentation));
}

#endif
